Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Allow tags or indices#1

Merged
rosesyrett merged 2 commits into
masterfrom
allowTagsOrIndices
Jul 13, 2022
Merged

Allow tags or indices#1
rosesyrett merged 2 commits into
masterfrom
allowTagsOrIndices

Conversation

@rosesyrett

Copy link
Copy Markdown
Contributor

Some of my routes in routes/UBCalculation.py delete or edit orientations/reflections in a pickled HklCalculation object. In Irakli's code, this can be done with both a tag for the desired orientation/reflection, and an index.

I have made changes to do the same here, so that the client using this API can request for an index in the list of orientations/reflections to be deleted, OR for a specific tag of orientations/reflections to be deleted. This worked with editing orientations/reflections because the tagOrIdx parameter was wrapped in a pydantic model - I've since realised that I needed to do the same for my delete routes as well, so I have made a simple deleteParams pydantic model to hold this information.

As a result, some tests have also changed. I have deleted the test_diffcalc_API.py file as well, as this was a dummy file.

@garryod garryod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, only real thought is that I reckon it'd be nice if the rest API took separate tag and idx fields, perhaps with a structure akin to:

class DeleteParams(BaseModel):
    tag: Optional[str]
    idx: Optional[int]

    @property ref(self) -> Union[int, str]:
        ...

Comment thread src/diffcalc_API/models/UBCalculation.py
@rosesyrett

Copy link
Copy Markdown
Contributor Author

I thought about doing this, the only problem is then I'd have to add extra validation to make sure the user definitely input either an index or a tag. Also, Irakli's functions that I call have just one parameter for this, which acts as both.

@garryod

garryod commented Jul 13, 2022

Copy link
Copy Markdown
Contributor

ought about doing this, the only problem is then I'd have to add extra validation to make sure the user definitely input either an index or a tag. Also, Irakli's functions that I call have just one parameter for this, which acts as both.

It would definitely add a bit of polish if you were to, but it's just that. Might be worth having a look at Irakli's code to see why this is done and if it would be better separated into two functions (one which takes an idx and one which takes a tag) so that validation can be moved downstream

@rosesyrett rosesyrett merged commit 6e1caec into master Jul 13, 2022
@rosesyrett rosesyrett deleted the allowTagsOrIndices branch July 13, 2022 15:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants